<%@ include file="/common/taglibs.jsp"%>
<head>
	<title><fmt:message key="userProfile.title"/></title>
	<script type="text/javascript" src="<c:url value='/scripts/selectbox.js'/>"></script>
</head>
<link href="${ctx}/ext/styles/validator/cmxform.css" rel="stylesheet"
	type="text/css">
	<script language="javascript" type="text/javascript"
		src="${ctx}/ext/scripts/validator/jquery.validate.js">
	</script>
	<script language="javascript" type="text/javascript"
		src="${ctx}/ext/scripts/validator/validateUtil.js">
	</script>
<script type="text/javascript">
jQuery.validator.setDefaults( {
	submitHandler : function() {
		document.userForm.submit;
	}
});

jQuery().ready(function() {
	
		jQuery("#roleForm").validate({
			rules:{
				rolename:{
					required: true
				}
			},
			messages:{
				rolename:{
					required: "<fmt:message key="validate.rolename.nul"/>"
				}
			}
		});
	});
</script>
<div class="box_big">

<form:form commandName="role" method="post" action="roleform.html" id="roleForm">
	<form:hidden path="roleid" />
	<input type="hidden" name="from" value="<c:out value="${param.from}"/>"/>
	<input type="hidden" name="method" value="<c:out value="${param.method}"/>"/>
	<div class="bj_biao">
		<h4>
			<fmt:message key="role.baseheader"/>:
		</h4>
	</div>
	<table border="0" cellspacing="0" cellpadding="0" class="table_cx2">
		<tr>
			<th width="80" class="fz_12"><fmt:message key="role.rolename"/><span class="required">*</span>:</th>
			<td width="200">
				<c:if test="${param.method eq 'Add'}">
					<form:input path="rolename" id="name" cssClass="text"/>
				</c:if>
				<c:if test="${param.method ne 'Add'}">
					<form:input path="rolename" id="name" cssClass="text" readonly="true"/>
				</c:if>
				<input type="hidden" name="operator" value="${param.method}"/>
				<input type="hidden" name="ptmeth" value="${ptmeth}"/>
				<input type="hidden" name="tz" value="${tzpage}"/>
				<input type="hidden" name="pagename" value="${pagename}"/>
			</td>
			<th width="140" class="fz_12"><fmt:message key="role.description"/>:</th>
			<td width="200"><form:input path="description" id="description" cssClass="text"/></td>
		  </tr>
	</table>
	<div class="bj_biao">
		<h4>
			<fmt:message key="role.assignAuthoriy"/>
		</h4>
	</div>

	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_cx2">
		<c:forEach var="au" items="${pauthoriylist}" varStatus="statu">
		<tr<c:if test="${statu.index%2==0}"> class="yellow"</c:if>>
			<td>
			
				<strong><input id="${au.authoriyname}" type="checkbox" name="permissons" onclick="selectAll('${au.authoriyname}child');" value="${au.authoriyname}"
				<c:forEach var="rp" items="${role.authoriy}">
				<c:if test="${rp!=null && rp.authoriyname==au.authoriyname}">checked="checked"</c:if>
				</c:forEach>
				>${au.description}:</strong>
				<c:forEach var="p" items="${availistpermissons}">
				<c:if test="${p.parentid==au.authoriyid}">
    			<input id="${au.authoriyname}child" name="permissons" type="checkbox" onclick="selectParent('${au.authoriyname}')"
						value="${p.authoriyname}"
						<c:forEach var="rp" items="${role.authoriy}">
						<c:if test="${rp!=null && rp.authoriyname==p.authoriyname}">checked="checked"</c:if>
						</c:forEach> />${p.description}
				</c:if>
				</c:forEach>
			</td>
		</tr>
		</c:forEach>
	</table>
	
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td align="center">
				<input type="submit" class="btn_blue2" name="save" value="<fmt:message key="button.save"/>" />
				<input type="button" class="btn_blue2" name="cancel" onclick="onCancel();" value="<fmt:message key="button.cancel"/>" />
			</td>
		</tr>
	</table>
</form:form>
</div>
<script type="text/javascript">
function selectAll(select){ 
  o=document.getElementsByName(select) 
  for(i=0;i<o.length;i++) 
    	o[i].checked=event.srcElement.checked; 
}

function selectParent(select){ 
	var node1 = jQuery("#"+select);
	node1.attr("checked","checked");
}
function onCancel()
{
	history.go(-1);
}
</script>